//
//  RCMerchantDetailSigninDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-20.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantDetailSigninDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCMerchantDetailSigninItem

@synthesize userName = _userName;
@synthesize score = _score;
@synthesize content = _content;
@synthesize dateTime = _dateTime;

-(id)init{
    self = [super init];
    if (self) {
        _userName = nil;
        _score = 0;
        _content = nil;
        _dateTime = nil;
    }
    return self;
}

-(void)dealloc{
    self.userName = nil;
    self.content = nil;
    self.dateTime = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCMerchantDetailSigninItem *retObject = nil;
    retObject = [[RCMerchantDetailSigninItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.userName = [data stringValueForKey:@"username" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.score = [data intValueForKey:@"score" defaultValue:0];
    retObject.content = [data stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.dateTime = [data stringValueForKey:@"datetime" defaultValue:nil operation:NSStringOperationTypeTrim];
    return [retObject autorelease];
}

@end

@implementation RCMerchantDetailSigninDataModel

@synthesize itemListArray = _itemListArray;
@synthesize total = _total;

-(id)init{
    self = [super init];
    if (self) {
        _itemListArray = nil;
        _total = 0;
    }
    return self;
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return nil;
    }
    
    NSArray *dictArray = [dict arrayValueForKey:@"items" defaultValue:nil];
    if (nil == dictArray || [dictArray count] == 0) {
        return nil;
    }
    RCMerchantDetailSigninDataModel *retObject = nil;
    retObject = [[RCMerchantDetailSigninDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.total = [dict intValueForKey:@"total" defaultValue:0];
    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:[dictArray count]];
    for (int i=0; i < [dictArray count]; i++) {
        NSDictionary *dictItem = [dictArray safeObjectAtIndex:i];
        if (nil == dictItem) {
            continue;
        }
        RCMerchantDetailSigninItem *item = [RCMerchantDetailSigninItem parseDataFromJSON:dictItem];
        if (nil == item) {
            continue;
        }
        [tempArray addObject:item];
    }
    retObject.itemListArray = [NSArray arrayWithArray:tempArray];
    [tempArray release];
    return [retObject autorelease];
}

@end
